package com.ruoyi.trainingManagement.controller;

import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.trainingManagement.domain.ClassSchedule;
import com.ruoyi.trainingManagement.service.IClassScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培养方案课程列表Controller
 *
 * @author chenxl
 * @date 2025-05-12
 */
@RestController
@RequestMapping("/trainingManagement/courseSchedule")
public class ClassScheduleController extends BaseController
{
    @Autowired
    private IClassScheduleService classScheduleService;

    /**
     * 查询培养方案课程列表列表
     */
    //@PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClassSchedule classSchedule)
    {
        startPage();
        List<ClassSchedule> list = classScheduleService.selectClassScheduleList(classSchedule);
        return getDataTable(list);
    }

    /**
     * 导出培养方案课程列表列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:export')")
    @Log(title = "培养方案课程列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClassSchedule classSchedule)
    {
        List<ClassSchedule> list = classScheduleService.selectClassScheduleList(classSchedule);
        ExcelUtil<ClassSchedule> util = new ExcelUtil<ClassSchedule>(ClassSchedule.class);
        util.exportExcel(response, list, "培养方案课程列表数据");
    }

    /**
     * 获取培养方案课程列表详细信息
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(classScheduleService.selectClassScheduleById(id));
    }

    /**
     * 新增培养方案课程列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:add')")
    @Log(title = "培养方案课程列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClassSchedule classSchedule)
    {
        return toAjax(classScheduleService.insertClassSchedule(classSchedule));
    }

    /**
     * 修改培养方案课程列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:edit')")
    @Log(title = "培养方案课程列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClassSchedule classSchedule)
    {
        return toAjax(classScheduleService.updateClassSchedule(classSchedule));
    }

    /**
     * 删除培养方案课程列表
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:remove')")
    @Log(title = "培养方案课程列表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(classScheduleService.deleteClassScheduleByIds(ids));
    }
    /**
     * 根据课程id获取培养方案列表
     *
     * @return
     */
    @PreAuthorize("@ss.hasPermi('trainingManagement:courseSchedule:list')")
    @GetMapping("/getClassScheduleByCourseId/{courseId}")
    public AjaxResult getClassScheduleByCourseId(@PathVariable String courseId)
    {   /* startPage();
        List<ClassSchedule> list = classScheduleService.selectClassScheduleList(classSchedule);
        return getDataTable(list);*/
//            return success(classScheduleService.getClassScheduleByCourseId(courseId));
        startPage();
        List<ClassSchedule> list = classScheduleService.getClassScheduleByCourseId(courseId);
        return AjaxResult.success(list);
    }
}
